package com.guigu.www.service.imp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.www.mapper.PayDetailsMapper;
import com.guigu.www.mapper.PayMapper;
import com.guigu.www.pojo.PayDetails;
import com.guigu.www.service.PayDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Service
public class PayDetailsServiceImpl extends ServiceImpl<PayDetailsMapper, PayDetails> implements PayDetailsService {
    //获取map
    @Autowired
    PayDetailsMapper payDetailsMapper;
    //流水号
    @Override
    //添加明细表数据
    public boolean addParByPayDetailds(List<PayDetails> payDetails) {
        int i=0;
        boolean f=false;
        for (PayDetails payDetail : payDetails) {
            //调用方法
            i+=payDetailsMapper.addParByPayDetailds(payDetail);
        }
        if(payDetails.size()==i){
            f=true;
        }

        return f;
    }

    @Override
    //查询当前出库的产品
    public PayDetails queryBypayDetailsByid(String productId, int id) {
        return payDetailsMapper.queryBypayDetailsByid(productId,id);
    }

    //修改明细表状态
    @Override
    public boolean updatepayDetailsfuid(String productId, int id) {
        return payDetailsMapper.updatepayDetailsfuid(productId,id)>0?true:false;
    }

    //修改当前出库的出库明细表数据
    @Override
    public boolean updatoutpeyPaydetailsBystatus(List<PayDetails> payDetails) {
        boolean f=false;
        for (PayDetails payDetail : payDetails) {
                if(Double.parseDouble(payDetail.getAmount())==payDetail.getWarehousing()){
                    payDetail.setPaidAmount("0");
                }
                payDetail.setPayTag("K002-3");
            //调用方法
            f=payDetailsMapper.updatoutpeyPaydetailsBystatus(payDetail)>0?true:false;
        }
        return f;

    }

    @Override
    public PayDetails queryBypayDetalisByid(int id, String productId) {
        return payDetailsMapper.queryBypayDetalisByid(id,productId);
    }

    @Override
    public PageInfo<PayDetails> querypayBydynamicinventiryall(int pageno, int pagesize, String productId) {
        //创建分页
        PageHelper.startPage(pageno,pagesize);
        //条件查询
        List<PayDetails> list=payDetailsMapper.querypayBydynamicinventiryall(productId);
        //创建apgeinfo
        PageInfo<PayDetails> pageInfo= new PageInfo<>(list);
        return pageInfo;
    }

}
